﻿/* 4. Write a program that reads two positive integer numbers and prints how many numbers p exist between them 
 * such that the reminder of the division by 5 is 0 (inclusive). Example: p(17,25) = 2. */

using System;

public class BetweenTwoIntegers
{
    public static int first;
    public static int second;
    public static int divisionBy;

    public static void Main()
    {
        int count;

        DataInput();
        Console.Write("p({0},{1})::{2} = ", first, second, divisionBy);
        
        if(divisionBy < 0)
            divisionBy = -divisionBy;

        if (second < first)
            Swap(first, second);

        if (second <= 0)
        {
            first = -first;
            second = -second;
            Swap(first, second);
        }

        if (first >= 0)
            count = (first % divisionBy + second - first) / divisionBy + (first % divisionBy == 0 ? 1 : 0);
        else
            count = (-first) / divisionBy + second / divisionBy + 1;

        Console.WriteLine(count);
    }

    public static void Swap(int a, int b)
    {
        b += a;
        a = b - a;
        b -= a;
    }

    public static void DataInput()
    {
        do
        {
            Console.Clear();
            Console.WriteLine("Enter successively three integers for divisor(!=0), first and second number:");
            if (int.TryParse(Console.ReadLine(), out divisionBy)
                    && (divisionBy != 0)
                        && int.TryParse(Console.ReadLine(), out first)
                            && (int.TryParse(Console.ReadLine(), out second)))
                break;
        } while (true);
    }
}